// app.js
App({
  onLaunch() {
    wx.cloud.init({
      env:'shop-9gu45y1p3f9a541f'
    })
    let temp = null
    if(temp = wx.getStorageSync('cartList')){
      this.globalData.cartList = temp
    }
    if(temp = wx.getStorageSync('goodsNumber')){
      this.globalData.goodsNumber = temp
    }
    if(temp = wx.getStorageSync('checkedList')){
      this.globalData.checkedList = temp
    }
    if(temp = wx.getStorageSync('userInfo')){
      this.globalData.cur_user = temp
    }
    //获取openid
    wx.cloud.callFunction({
       name:'getOpenid'
    }).then(res=>{
      this.globalData.openid = res.result.openid
      const db = wx.cloud.database()
      db.collection('users').where({
        _openid: res.result.openid,
      }).get({
        success: function(params) {
          if(params.data.length > 0)
            this.globalData.cur_user = params.data[0]
        }
      })
      console.log(res.result.openid)
    })
  },
  globalData: {
    cartList: [],
    goodsNumber: [],//商品数量数据
    checkedList: [],//是否选中列表
    orderList: [],//订单列表(最后要买的订单列表)
    openid:null,//用户标识符
    rString:'',
    cur_user: ''//用户名
  }
})
